home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / st_lib.c < prev    next >
C/C++ Source or Header  |  1998-02-14  |  5KB  |  298 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    The status bar widget code.
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24.  
  25. static const char
  26. rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
  27.  
  28. #include <ctype.h>
  29.  
  30. #include "doomdef.h"
  31. #include "doomstat.h"
  32.  
  33. #include "z_zone.h"
  34. #include "v_video.h"
  35.  
  36. #include "m_swap.h"
  37.  
  38. #include "i_system.h"
  39.  
  40. #include "w_wad.h"
  41.  
  42. #include "st_stuff.h"
  43. #include "st_lib.h"
  44. #include "r_local.h"
  45.  
  46.  
  47. // in AM_map.c
  48. extern boolean        automapactive; 
  49.  
  50.  
  51.  
  52.  
  53. //
  54. // Hack display negative frags.
  55. //  Loads and store the stminus lump.
  56. //
  57. patch_t*        sttminus = NULL;
  58.  
  59. void STlib_init(void)
  60. {
  61.     int i;
  62.  
  63.     if ((i = W_CheckNumForName("STTMINUS")) != -1)
  64.         sttminus = (patch_t *) W_CacheLumpNum(i, PU_STATIC);
  65. }
  66.  
  67.  
  68. // ?
  69. void
  70. STlib_initNum
  71. ( st_number_t*        n,
  72.   int            x,
  73.   int            y,
  74.   patch_t**        pl,
  75.   int*            num,
  76.   boolean*        on,
  77.   int            width )
  78. {
  79.     n->x    = x;
  80.     n->y    = y;
  81.     n->oldnum    = 0;
  82.     n->width    = width;
  83.     n->num    = num;
  84.     n->on    = on;
  85.     n->p    = pl;
  86. }
  87.  
  88.  
  89. // 
  90. // A fairly efficient way to draw a number
  91. //  based on differences from the old number.
  92. // Note: worth the trouble?
  93. //
  94. void
  95. STlib_drawNum
  96. ( st_number_t*    n,
  97.   boolean    refresh )
  98. {
  99.  
  100.     int        numdigits = n->width;
  101.     int        num = *n->num;
  102.     
  103.     int        w = SWAPSHORT(n->p[0]->width);
  104.     int        h = SWAPSHORT(n->p[0]->height);
  105.     int        x = n->x;
  106.     
  107.     int        neg;
  108.  
  109.     n->oldnum = *n->num;
  110.  
  111.     neg = num < 0;
  112.  
  113.     if (neg)
  114.     {
  115.     if (numdigits == 2 && num < -9)
  116.         num = -9;
  117.     else if (numdigits == 3 && num < -99)
  118.         num = -99;
  119.     
  120.     num = -num;
  121.     }
  122.  
  123.     // clear the area
  124.     x = n->x - numdigits*w;
  125.  
  126.     if (n->y - ST_Y < 0)
  127.     I_Error("drawNum: n->y - ST_Y < 0");
  128.  
  129.     V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
  130.  
  131.     // if non-number, do not draw it
  132.     if (num == 1994)
  133.     return;
  134.  
  135.     x = n->x;
  136.  
  137.     // in the special case of 0, you draw 0
  138.     if (!num)
  139.     V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
  140.  
  141.     // draw the new number
  142.     while (num && numdigits--)
  143.     {
  144.     x -= w;
  145.     V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
  146.     num /= 10;
  147.     }
  148.  
  149.     // draw a minus sign if necessary
  150.     if (neg && sttminus != NULL)
  151.     V_DrawPatch(x - 8, n->y, FG, sttminus);
  152. }
  153.  
  154.  
  155. //
  156. void
  157. STlib_updateNum
  158. ( st_number_t*        n,
  159.   boolean        refresh )
  160. {
  161.     if (*n->on) STlib_drawNum(n, refresh);
  162. }
  163.  
  164.  
  165. //
  166. void
  167. STlib_initPercent
  168. ( st_percent_t*        p,
  169.   int            x,
  170.   int            y,
  171.   patch_t**        pl,
  172.   int*            num,
  173.   boolean*        on,
  174.   patch_t*        percent )
  175. {
  176.     STlib_initNum(&p->n, x, y, pl, num, on, 3);
  177.     p->p = percent;
  178. }
  179.  
  180.  
  181.  
  182.  
  183. void
  184. STlib_updatePercent
  185. ( st_percent_t*        per,
  186.   int            refresh )
  187. {
  188.     if (refresh && *per->n.on)
  189.     V_DrawPatch(per->n.x, per->n.y, FG, per->p);
  190.     
  191.     STlib_updateNum(&per->n, refresh);
  192. }
  193.  
  194.  
  195.  
  196. void
  197. STlib_initMultIcon
  198. ( st_multicon_t*    i,
  199.   int            x,
  200.   int            y,
  201.   patch_t**        il,
  202.   int*            inum,
  203.   boolean*        on )
  204. {
  205.     i->x    = x;
  206.     i->y    = y;
  207.     i->oldinum     = -1;
  208.     i->inum    = inum;
  209.     i->on    = on;
  210.     i->p    = il;
  211. }
  212.  
  213.  
  214.  
  215. void
  216. STlib_updateMultIcon
  217. ( st_multicon_t*    mi,
  218.   boolean        refresh )
  219. {
  220.     int            w;
  221.     int            h;
  222.     int            x;
  223.     int            y;
  224.  
  225.     if (*mi->on
  226.     && (mi->oldinum != *mi->inum || refresh)
  227.     && (*mi->inum!=-1))
  228.     {
  229.     if (mi->oldinum != -1)
  230.     {
  231.         x = mi->x - SWAPSHORT(mi->p[mi->oldinum]->leftoffset);
  232.         y = mi->y - SWAPSHORT(mi->p[mi->oldinum]->topoffset);
  233.         w = SWAPSHORT(mi->p[mi->oldinum]->width);
  234.         h = SWAPSHORT(mi->p[mi->oldinum]->height);
  235.  
  236.         if (y - ST_Y < 0)
  237.         I_Error("updateMultIcon: y - ST_Y < 0");
  238.  
  239.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  240.     }
  241.     V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
  242.     mi->oldinum = *mi->inum;
  243.     }
  244. }
  245.  
  246.  
  247.  
  248. void
  249. STlib_initBinIcon
  250. ( st_binicon_t*        b,
  251.   int            x,
  252.   int            y,
  253.   patch_t*        i,
  254.   boolean*        val,
  255.   boolean*        on )
  256. {
  257.     b->x    = x;
  258.     b->y    = y;
  259.     b->oldval    = 0;
  260.     b->val    = val;
  261.     b->on    = on;
  262.     b->p    = i;
  263. }
  264.  
  265.  
  266.  
  267. void
  268. STlib_updateBinIcon
  269. ( st_binicon_t*        bi,
  270.   boolean        refresh )
  271. {
  272.     int            x;
  273.     int            y;
  274.     int            w;
  275.     int            h;
  276.  
  277.     if (*bi->on
  278.     && (bi->oldval != *bi->val || refresh))
  279.     {
  280.     x = bi->x - SWAPSHORT(bi->p->leftoffset);
  281.     y = bi->y - SWAPSHORT(bi->p->topoffset);
  282.     w = SWAPSHORT(bi->p->width);
  283.     h = SWAPSHORT(bi->p->height);
  284.  
  285.     if (y - ST_Y < 0)
  286.         I_Error("updateBinIcon: y - ST_Y < 0");
  287.  
  288.     if (*bi->val)
  289.         V_DrawPatch(bi->x, bi->y, FG, bi->p);
  290.     else
  291.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  292.  
  293.     bi->oldval = *bi->val;
  294.     }
  295.  
  296. }
  297.  
  298.